package org.example.redis;

import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

public class RedissonBloomFilter {
    public static void main(String[] args) {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://192.168.204.117:6379");
        config.useSingleServer().setPassword("Infra5_Gep0int");
        RedissonClient redissonClient = Redisson.create(config);

        // 测试布隆过滤器
        RBloomFilter<String> bloomFilter = redissonClient.getBloomFilter("phoneList");
        // 预计存入元素100000000L，误差率在3%
        bloomFilter.tryInit(100000000L, 0.03);

        bloomFilter.add("10086");

        System.out.println(bloomFilter.contains("10086"));
        System.out.println(bloomFilter.contains("123456"));

        redissonClient.shutdown();
    }
}
